@@ -14,7 +14,7 @@ from paginator import pagination  | 
            ||
| 14 | 14 | 
                from TimeConvert import TimeConvert as tc  | 
            
| 15 | 15 | 
                 | 
            
| 16 | 16 | 
                from account.models import UserInfo  | 
            
| 17 | 
                -from coupon.models import UserCouponInfo  | 
            |
| 17 | 
                +from coupon.models import UserCouponInfo, CouponInfo  | 
            |
| 18 | 18 | 
                from integral.models import SaleclerkSubmitLogInfo  | 
            
| 19 | 19 | 
                from logs.models import MchInfoEncryptLogInfo  | 
            
| 20 | 20 | 
                from mch.models import AdministratorInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, ModelInfo  | 
            
                @@ -969,3 +969,165 @@ def member_activity_share_list(request):  | 
            ||
| 969 | 969 | 
                'total_integral': total_integral  | 
            
| 970 | 970 | 
                })  | 
            
| 971 | 971 | 
                 | 
            
| 972 | 
                +def coupon_list(request):  | 
            |
| 973 | 
                +    brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
               | 
            |
| 974 | 
                +    admin_id = request.POST.get('admin_id', '')
               | 
            |
| 975 | 
                +    title = request.POST.get('title', '')
               | 
            |
| 976 | 
                +    start_time = request.POST.get('start_time', '')
               | 
            |
| 977 | 
                +    end_time = request.POST.get('end_time', '')
               | 
            |
| 978 | 
                +    page = request.POST.get('page', 1)
               | 
            |
| 979 | 
                +    num = request.POST.get('num', 20)
               | 
            |
| 980 | 
                +  | 
            |
| 981 | 
                + if brand_id != settings.KODO_DEFAULT_BRAND_ID:  | 
            |
| 982 | 
                + return response(ProductBrandStatusCode.BRAND_NOT_MATCH)  | 
            |
| 983 | 
                +  | 
            |
| 984 | 
                + try:  | 
            |
| 985 | 
                + administrator = AdministratorInfo.objects.get(admin_id=admin_id, user_status=AdministratorInfo.ACTIVATED, status=True)  | 
            |
| 986 | 
                + except AdministratorInfo.DoesNotExist:  | 
            |
| 987 | 
                + return response(AdministratorStatusCode.ADMINISTRATOR_NOT_FOUND)  | 
            |
| 988 | 
                +  | 
            |
| 989 | 
                + logs = CouponInfo.objects.filter(coupon_title__icontains=title, status=True)  | 
            |
| 990 | 
                +  | 
            |
| 991 | 
                + if start_time and end_time:  | 
            |
| 992 | 
                + start_time = datetime.strptime(start_time, '%Y%m%d')  | 
            |
| 993 | 
                + end_time = datetime.strptime(end_time + ' 23:59:59', '%Y%m%d %H:%M:%S')  | 
            |
| 994 | 
                + logs = logs.filter(created_at__range=(start_time, end_time))  | 
            |
| 995 | 
                +  | 
            |
| 996 | 
                +    logs = logs.order_by('-created_at')
               | 
            |
| 997 | 
                +  | 
            |
| 998 | 
                + count = logs.count()  | 
            |
| 999 | 
                + logs, left = pagination(logs, page, num)  | 
            |
| 1000 | 
                + logs = [log.admindata for log in logs]  | 
            |
| 1001 | 
                +    return response(200, 'Get CouponInfo List Success', u'获取劵列表成功', data={
               | 
            |
| 1002 | 
                + 'logs': logs,  | 
            |
| 1003 | 
                + 'left': left,  | 
            |
| 1004 | 
                + 'count': count  | 
            |
| 1005 | 
                + })  | 
            |
| 1006 | 
                +  | 
            |
| 1007 | 
                +def coupon_details(request):  | 
            |
| 1008 | 
                +    brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
               | 
            |
| 1009 | 
                +    admin_id = request.POST.get('admin_id', '')
               | 
            |
| 1010 | 
                +    coupon_id = request.POST.get('coupon_id', '')
               | 
            |
| 1011 | 
                + if brand_id != settings.KODO_DEFAULT_BRAND_ID:  | 
            |
| 1012 | 
                + return response(ProductBrandStatusCode.BRAND_NOT_MATCH)  | 
            |
| 1013 | 
                +  | 
            |
| 1014 | 
                + try:  | 
            |
| 1015 | 
                + administrator = AdministratorInfo.objects.get(admin_id=admin_id, user_status=AdministratorInfo.ACTIVATED, status=True)  | 
            |
| 1016 | 
                + except AdministratorInfo.DoesNotExist:  | 
            |
| 1017 | 
                + return response(AdministratorStatusCode.ADMINISTRATOR_NOT_FOUND)  | 
            |
| 1018 | 
                +  | 
            |
| 1019 | 
                + try:  | 
            |
| 1020 | 
                + log = CouponInfo.objects.get(coupon_id=coupon_id)  | 
            |
| 1021 | 
                + except:  | 
            |
| 1022 | 
                + return response()  | 
            |
| 1023 | 
                +  | 
            |
| 1024 | 
                + log = log.admindetails  | 
            |
| 1025 | 
                +  | 
            |
| 1026 | 
                +    return response(200, 'Get Member Activity Record Details Success', u'获取会员活动详情成功', data={
               | 
            |
| 1027 | 
                + 'log': log,  | 
            |
| 1028 | 
                + })  | 
            |
| 1029 | 
                +  | 
            |
| 1030 | 
                +def coupon_create(request):  | 
            |
| 1031 | 
                +    brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
               | 
            |
| 1032 | 
                +    admin_id = request.POST.get('admin_id', '')
               | 
            |
| 1033 | 
                +    coupon_title = request.POST.get('coupon_title', '')
               | 
            |
| 1034 | 
                +    coupon_detail = request.POST.get('coupon_detail', '')
               | 
            |
| 1035 | 
                +    coupon_value = int(request.POST.get('coupon_value', 0))
               | 
            |
| 1036 | 
                +    coupon_image = request.POST.get('coupon_image', '')
               | 
            |
| 1037 | 
                +    coupon_expire_type = int(request.POST.get('coupon_expire_type', 0))
               | 
            |
| 1038 | 
                +    coupon_valid_period = int(request.POST.get('coupon_valid_period', 0))
               | 
            |
| 1039 | 
                +    coupon_expire_at = request.POST.get('coupon_expire_at', '')
               | 
            |
| 1040 | 
                +    is_coupon_admin_writeoff = int(request.POST.get('is_coupon_admin_writeoff', 1))
               | 
            |
| 1041 | 
                +  | 
            |
| 1042 | 
                + if brand_id != settings.KODO_DEFAULT_BRAND_ID:  | 
            |
| 1043 | 
                + return response(ProductBrandStatusCode.BRAND_NOT_MATCH)  | 
            |
| 1044 | 
                +  | 
            |
| 1045 | 
                + try:  | 
            |
| 1046 | 
                + administrator = AdministratorInfo.objects.get(admin_id=admin_id, user_status=AdministratorInfo.ACTIVATED, status=True)  | 
            |
| 1047 | 
                + except AdministratorInfo.DoesNotExist:  | 
            |
| 1048 | 
                + return response(AdministratorStatusCode.ADMINISTRATOR_NOT_FOUND)  | 
            |
| 1049 | 
                +  | 
            |
| 1050 | 
                + print coupon_image  | 
            |
| 1051 | 
                +  | 
            |
| 1052 | 
                + info = CouponInfo.objects.create(  | 
            |
| 1053 | 
                + brand_id = brand_id,  | 
            |
| 1054 | 
                + coupon_title = coupon_title,  | 
            |
| 1055 | 
                + coupon_detail = coupon_detail,  | 
            |
| 1056 | 
                + coupon_value = coupon_value,  | 
            |
| 1057 | 
                + coupon_image = coupon_image,  | 
            |
| 1058 | 
                + coupon_expire_type = coupon_expire_type,  | 
            |
| 1059 | 
                + coupon_valid_period = coupon_valid_period,  | 
            |
| 1060 | 
                + is_coupon_admin_writeoff = is_coupon_admin_writeoff  | 
            |
| 1061 | 
                + )  | 
            |
| 1062 | 
                +  | 
            |
| 1063 | 
                + if coupon_expire_at:  | 
            |
| 1064 | 
                + info.coupon_expire_at = datetime.strptime(coupon_expire_at + ' 23:59:59', '%Y-%m-%d %H:%M:%S')  | 
            |
| 1065 | 
                + info.save()  | 
            |
| 1066 | 
                +  | 
            |
| 1067 | 
                + return response(200, 'CouponInfo Create Success', u'劵创建成功')  | 
            |
| 1068 | 
                +  | 
            |
| 1069 | 
                +def coupon_update(request):  | 
            |
| 1070 | 
                +    brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
               | 
            |
| 1071 | 
                +    admin_id = request.POST.get('admin_id', '')
               | 
            |
| 1072 | 
                +    coupon_id = request.POST.get('coupon_id', '')
               | 
            |
| 1073 | 
                +    coupon_title = request.POST.get('coupon_title', '')
               | 
            |
| 1074 | 
                +    coupon_detail = request.POST.get('coupon_detail', '')
               | 
            |
| 1075 | 
                +    coupon_value = int(request.POST.get('coupon_value', 0))
               | 
            |
| 1076 | 
                +    coupon_image = request.POST.get('coupon_image', '')
               | 
            |
| 1077 | 
                +    coupon_expire_type = int(request.POST.get('coupon_expire_type', 0))
               | 
            |
| 1078 | 
                +    coupon_valid_period = int(request.POST.get('coupon_valid_period', 0))
               | 
            |
| 1079 | 
                +    coupon_expire_at = request.POST.get('coupon_expire_at', '')
               | 
            |
| 1080 | 
                +    is_coupon_admin_writeoff = int(request.POST.get('is_coupon_admin_writeoff', 1))
               | 
            |
| 1081 | 
                +  | 
            |
| 1082 | 
                + if brand_id != settings.KODO_DEFAULT_BRAND_ID:  | 
            |
| 1083 | 
                + return response(ProductBrandStatusCode.BRAND_NOT_MATCH)  | 
            |
| 1084 | 
                +  | 
            |
| 1085 | 
                + try:  | 
            |
| 1086 | 
                + administrator = AdministratorInfo.objects.get(admin_id=admin_id, user_status=AdministratorInfo.ACTIVATED, status=True)  | 
            |
| 1087 | 
                + except AdministratorInfo.DoesNotExist:  | 
            |
| 1088 | 
                + return response(AdministratorStatusCode.ADMINISTRATOR_NOT_FOUND)  | 
            |
| 1089 | 
                +  | 
            |
| 1090 | 
                + try:  | 
            |
| 1091 | 
                + log = CouponInfo.objects.get(coupon_id=coupon_id, status=True)  | 
            |
| 1092 | 
                + except:  | 
            |
| 1093 | 
                + return response()  | 
            |
| 1094 | 
                +  | 
            |
| 1095 | 
                + print coupon_image  | 
            |
| 1096 | 
                +  | 
            |
| 1097 | 
                + log.brand_id = brand_id  | 
            |
| 1098 | 
                + log.coupon_title = coupon_title  | 
            |
| 1099 | 
                + log.coupon_detail = coupon_detail  | 
            |
| 1100 | 
                + log.coupon_value = coupon_value  | 
            |
| 1101 | 
                + log.coupon_image = coupon_image  | 
            |
| 1102 | 
                + log.coupon_expire_type = coupon_expire_type  | 
            |
| 1103 | 
                + log.coupon_valid_period = coupon_valid_period  | 
            |
| 1104 | 
                + if coupon_expire_at:  | 
            |
| 1105 | 
                + log.coupon_expire_at = datetime.strptime(coupon_expire_at + ' 23:59:59', '%Y-%m-%d %H:%M:%S')  | 
            |
| 1106 | 
                + log.is_coupon_admin_writeoff = is_coupon_admin_writeoff  | 
            |
| 1107 | 
                + log.save()  | 
            |
| 1108 | 
                +  | 
            |
| 1109 | 
                + return response(200, 'CouponInfo Update Success', u'劵更新成功')  | 
            |
| 1110 | 
                +  | 
            |
| 1111 | 
                +def coupon_delete(request):  | 
            |
| 1112 | 
                +    brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
               | 
            |
| 1113 | 
                +    admin_id = request.POST.get('admin_id', '')
               | 
            |
| 1114 | 
                +    coupon_id = request.POST.get('activity_id', '')
               | 
            |
| 1115 | 
                +  | 
            |
| 1116 | 
                + if brand_id != settings.KODO_DEFAULT_BRAND_ID:  | 
            |
| 1117 | 
                + return response(ProductBrandStatusCode.BRAND_NOT_MATCH)  | 
            |
| 1118 | 
                +  | 
            |
| 1119 | 
                + try:  | 
            |
| 1120 | 
                + administrator = AdministratorInfo.objects.get(admin_id=admin_id, user_status=AdministratorInfo.ACTIVATED, status=True)  | 
            |
| 1121 | 
                + except AdministratorInfo.DoesNotExist:  | 
            |
| 1122 | 
                + return response(AdministratorStatusCode.ADMINISTRATOR_NOT_FOUND)  | 
            |
| 1123 | 
                +  | 
            |
| 1124 | 
                + try:  | 
            |
| 1125 | 
                + log = CouponInfo.objects.get(coupon_id=coupon_id, status=True)  | 
            |
| 1126 | 
                + except:  | 
            |
| 1127 | 
                + return response()  | 
            |
| 1128 | 
                +  | 
            |
| 1129 | 
                + log.status = False  | 
            |
| 1130 | 
                + log.save()  | 
            |
| 1131 | 
                +  | 
            |
| 1132 | 
                + return response(200, 'CouponInfo Delete Success', u'劵删除成功')  | 
            |
| 1133 | 
                +  | 
            
                @@ -333,6 +333,11 @@ urlpatterns += [  | 
            ||
| 333 | 333 | 
                url(r'^admin/member/activity/create$', admin_views.member_activity_create, name='member_activity_create'),  | 
            
| 334 | 334 | 
                url(r'^admin/member/activity/share/list$', admin_views.member_activity_share_list, name='member_activity_share_list'),  | 
            
| 335 | 335 | 
                 | 
            
| 336 | 
                + url(r'^admin/coupon/list$', admin_views.coupon_list, name='coupon_list'),  | 
            |
| 337 | 
                + url(r'^admin/coupon/details$', admin_views.coupon_details, name='coupon_details'),  | 
            |
| 338 | 
                + url(r'^admin/coupon/create$', admin_views.coupon_create, name='coupon_create'),  | 
            |
| 339 | 
                + url(r'^admin/coupon/update$', admin_views.coupon_update, name='coupon_update'),  | 
            |
| 340 | 
                + url(r'^admin/coupon/delete$', admin_views.coupon_delete, name='coupon_delete'),  | 
            |
| 336 | 341 | 
                ]  | 
            
| 337 | 342 | 
                 | 
            
| 338 | 343 | 
                urlpatterns += [  | 
            
                @@ -56,6 +56,36 @@ class CouponInfo(BaseModelMixin):  | 
            ||
| 56 | 56 | 
                if self.coupon_expire_type == CouponInfo.FIXED_EXPIRED_TIME:  | 
            
| 57 | 57 | 
                return self.coupon_expire_at  | 
            
| 58 | 58 | 
                return tc.utc_datetime(days=self.coupon_valid_period)  | 
            
| 59 | 
                +  | 
            |
| 60 | 
                + @property  | 
            |
| 61 | 
                + def admindata(self):  | 
            |
| 62 | 
                +        return {
               | 
            |
| 63 | 
                + 'coupon_id': self.coupon_id,  | 
            |
| 64 | 
                + 'coupon_title': self.coupon_title,  | 
            |
| 65 | 
                + 'coupon_value': self.coupon_value,  | 
            |
| 66 | 
                + 'coupon_image': self.coupon_image_url,  | 
            |
| 67 | 
                + 'coupon_path': self.coupon_image_path,  | 
            |
| 68 | 
                + 'coupon_expire_type': self.coupon_expire_type,  | 
            |
| 69 | 
                + 'coupon_valid_period': self.coupon_valid_period,  | 
            |
| 70 | 
                + 'coupon_expire_at': tc.local_string(utc_dt=self.coupon_expire_at, format='%Y-%m-%d'),  | 
            |
| 71 | 
                + 'is_coupon_admin_writeoff': self.is_coupon_admin_writeoff,  | 
            |
| 72 | 
                + 'created_at': tc.local_string(utc_dt=self.created_at, format='%Y-%m-%d %H:%M:%S'),  | 
            |
| 73 | 
                + }  | 
            |
| 74 | 
                +  | 
            |
| 75 | 
                + @property  | 
            |
| 76 | 
                + def admindetails(self):  | 
            |
| 77 | 
                +        return {
               | 
            |
| 78 | 
                + 'coupon_id': self.coupon_id,  | 
            |
| 79 | 
                + 'coupon_title': self.coupon_title,  | 
            |
| 80 | 
                + 'coupon_value': self.coupon_value,  | 
            |
| 81 | 
                + 'coupon_detail': self.coupon_detail,  | 
            |
| 82 | 
                + 'coupon_image': self.coupon_image_url,  | 
            |
| 83 | 
                + 'coupon_path': self.coupon_image_path,  | 
            |
| 84 | 
                + 'coupon_expire_type': self.coupon_expire_type,  | 
            |
| 85 | 
                + 'coupon_valid_period': self.coupon_valid_period,  | 
            |
| 86 | 
                + 'coupon_expire_at': tc.local_string(utc_dt=self.coupon_expire_at, format='%Y-%m-%d'),  | 
            |
| 87 | 
                + 'is_coupon_admin_writeoff': self.is_coupon_admin_writeoff  | 
            |
| 88 | 
                + }  | 
            |
| 59 | 89 | 
                 | 
            
| 60 | 90 | 
                 | 
            
| 61 | 91 | 
                class UserCouponInfo(BaseModelMixin):  |